//-------------------------------------------------------------------
//	Copyright (c) 2013  Zhirnov Andrey
//	This file is part of the "Noise Library" project.
//	See copyright notice in "linNoiseCL.h".
//-------------------------------------------------------------------

#pragma once

#include "CProgram.h"

namespace Noise
{

	//
	// OpenCL Program
	//

	class CProgramCL : public CProgram
	{
	// variables
	private:
		CLProgram		_prog;
		CLKernel		_kernel;
		string			_compileLog;
		binary_array_t	_binarySrc;


	// methods
	private:
		bool _GetOptions (EBuildOptions options, cl_prog_options::type &eOpFlags, string &sOptions) const;
		void _AddPreProcessor (EBuildOptions options);
		void _AddProgramMainSrc (CSourcePtr source);
		void _CreateDefaultOutput (CSourcePtr source, CSourcePtr &outSource);

		bool _RenderImageCL (cl_mem imageId, const svec3 &offset, const svec3 &dim);

	public:
		CProgramCL ();
		~CProgramCL ();

		virtual void Delete ();

		virtual EResult Build (CSourcePtr source, EBuildOptions options);

		//virtual EResult GetReal (EProgramQuery pname, real *v, int count) const;
		virtual EResult GetInteger (EProgramQuery pname, int *v, int count) const;
		virtual EResult GetString (EProgramQuery pname, char *buf, int length) const;
		
		virtual EResult RenderToMemory (const uvec3 &dim, const uvec2 &sizes, EPixelFormat format, EPixelType type, void *pixels);
		virtual EResult RenderToImageCL (cl_mem imageId);
		virtual EResult RenderToSubImageCL (cl_mem imageId, const svec3 &offset, const svec3 &dim);
		virtual EResult RenderToTextureGL (GLenum target, GLuint id, int level);
		virtual EResult RenderToTextureDX (void *dxTex);

		static bool CreateProgram (CProgramPtr &prog, CContext *context, EProgram type);

		static const uni_array<const Format> GetSupportedFormats ();
	};


}	// Noise
